package com.example.usermanagementsystem.service;

import com.example.usermanagementsystem.domain.Employee;
import com.example.usermanagementsystem.mapper.EmployeeMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * springboot整合redis
 */
@Service
public class EmployeeServiceImpl implements EmployeeService{

    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private RedisTemplate<String, Employee> redisTemplate;

    @Qualifier("redisTemplate")
    @Autowired
    private RedisTemplate redisTemplateString;

    private final static Logger logger = LoggerFactory.getLogger(EmployeeServiceImpl.class);


    public Employee queryById(int id) {
        redisTemplateString.opsForValue().set("aaa","aaaa");
        Employee employee = employeeMapper.queryById(id);
        this.redisTemplate.opsForValue().set("employee-" + employee.getId() ,employee);
        System.out.println((redisTemplate.opsForValue().get("employee-" + employee.getId())));
        return employee;
    }


    public List<Employee> queryAll() {
        logger.info("1111111111111111111111");
        return employeeMapper.queryAll();
    }
}
